package com.winning.pmph.vo;

import com.winning.pmph.enumeration.ReturnCode;
import com.winning.pmph.utils.LocalDateTimeUtil;
import lombok.Data;

@Data
public class ResultData<T> {
    /**
     * 结果状态
     */
    private int status;
    private String message;
    private T data;
    private String timestamp;

    public ResultData() {
        this.timestamp = LocalDateTimeUtil.getNowAsString();
    }

    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(ReturnCode.RC200.getCode());
        resultData.setMessage(ReturnCode.RC200.getMessage());
        resultData.setData(data);
        if (data instanceof String) {
            resultData.setMessage(data.toString());
            resultData.setData(null);
        }
        return resultData;
    }

    public static <T> ResultData<T> fail(String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(ReturnCode.RC500.getCode());
        resultData.setMessage(message);
        return resultData;
    }
}
